﻿using Microsoft.Practices.Prism.Regions;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Ezpay.UI.ViewModels
{
    class HousingAgencyViewModel : INavigationAware
    {
        public string Name { get; set; }

        public List<HousingAgencyCustomerViewModel> Customers { get; set; }

        private IRegionManager _regionManager;
        public HousingAgencyViewModel(IRegionManager regionManager)
        {
            _regionManager = regionManager;
        }

        public bool IsNavigationTarget(NavigationContext navigationContext)
        {
            return navigationContext.Parameters["ID"] == Name;
        }

        public void OnNavigatedFrom(NavigationContext navigationContext)
        {
            if (IsNavigationTarget(navigationContext))
                return;

            navigationContext.NavigationService.Region.Remove(this);
        }

        public void OnNavigatedTo(NavigationContext navigationContext)
        {
            Name = navigationContext.Parameters["ID"];

            Customers = GlobalDB.GetCustomersForHousingAgency(Name).Select(x => new HousingAgencyCustomerViewModel(_regionManager)
            {
                CustomerID = x.CustomerID,
                FirstName = x.FirstName,
                LastName = x.LastName,
                PrimaryEmail = x.PrimaryEmail
            }).ToList();
        }
    }
}
